package com.salestax.core.tests;

import java.math.BigDecimal;
import java.math.MathContext;

import junit.framework.TestCase;

import com.salestax.core.Product;
import com.salestax.core.ShoppingList;
import com.salestax.core.specific.product.Book;
import com.salestax.core.specific.product.FoodProduct;
import com.salestax.core.specific.product.ImportedProduct;
import com.salestax.core.specific.product.MedicalProduct;
import com.salestax.core.specific.product.NormalProduct;

public class TestConcreteObject extends TestCase {
	
	private ShoppingList shoppingList = new ShoppingList();
	private static double delta = 0.05;
	
	public void testStart(){
		Product book = new Book("book",12.49,1);
		Product musicCD = new NormalProduct("nlormal",14.99,1);
		Product chocolateBar = new FoodProduct("",0.85,1);
		shoppingList.addProduct(book).addProduct(musicCD).addProduct(chocolateBar);

		assertEquals("12.49", book.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("16.49", musicCD.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("0.85", chocolateBar.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());

		assertEquals("29.83", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("1.50", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}
	
	public void testImported() {
		Product importedChocolates = new ImportedProduct("",1,new FoodProduct("",10.00,1));
		Product importedPerfumes = new ImportedProduct("",1,new NormalProduct("",47.50,1));
		shoppingList.addProduct(importedChocolates).addProduct(importedPerfumes);

		assertEquals("10.50", importedChocolates.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("54.65", importedPerfumes.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());

		assertEquals("65.15", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("7.65", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}
	
	public void testImportedAndSalesTax() {
		Product importedPerfume = new ImportedProduct("",1,new NormalProduct("",27.99,1));
		Product perfume = new NormalProduct("",18.99,1);
		Product hedachePill = new MedicalProduct("",9.75,1);
		Product importedChocolate = new ImportedProduct("",1,new FoodProduct("",11.25,1));
		shoppingList.addProduct(importedPerfume).addProduct(perfume).addProduct(
				hedachePill).addProduct(importedChocolate);

		assertEquals("32.19", importedPerfume.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("20.89", perfume.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("9.75", hedachePill.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("11.85", importedChocolate.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());

		assertEquals("6.70", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("74.68", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}	
}
